package com.woniu.cinema.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.woniu.common.annotation.Log;
import com.woniu.common.core.controller.BaseController;
import com.woniu.common.core.domain.AjaxResult;
import com.woniu.common.enums.BusinessType;
import com.woniu.cinema.domain.Seat;
import com.woniu.cinema.service.SeatService;
import com.woniu.common.utils.poi.ExcelUtil;
import com.woniu.common.core.page.TableDataInfo;

/**
 * 座位信息Controller
 *
 * @author yy
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/cinema/seat")
public class SeatController extends BaseController
{
    @Autowired
    private SeatService seatService;

    /**
     * 查询座位信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Seat seat)
    {
        startPage();
        List<Seat> list = seatService.selectSeatList(seat);
        return getDataTable(list);
    }

    /**
     * 导出座位信息列表
     */
    @Log(title = "座位信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Seat seat)
    {
        List<Seat> list = seatService.selectSeatList(seat);
        ExcelUtil<Seat> util = new ExcelUtil<Seat>(Seat.class);
        return util.exportExcel(list, "seat");
    }

    /**
     * 获取座位信息详细信息
     */
    @GetMapping(value = "/{seatId}")
    public AjaxResult getInfo(@PathVariable("seatId") Integer seatId)
    {
        return AjaxResult.success(seatService.selectSeatById(seatId));
    }

    @GetMapping(value = "web/querySeatListByHallMovieId")
    public AjaxResult querySeatListByHallMovieId( Integer hallMovieId)
    {
        return AjaxResult.success(seatService.querySeatListByHallMovieId(hallMovieId));
    }

    /**
     * 新增座位信息
     */
    @Log(title = "座位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Seat seat)
    {
        return toAjax(seatService.insertSeat(seat));
    }

    /**
     * 修改座位信息
     */
    @Log(title = "座位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Seat seat)
    {
        return toAjax(seatService.updateSeat(seat));
    }

    /**
     * 删除座位信息
     */
    @Log(title = "座位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seatIds}")
    public AjaxResult remove(@PathVariable Integer[] seatIds)
    {
        return toAjax(seatService.deleteSeatByIds(seatIds));
    }


    //批量更新座位状态
    @RequestMapping("feign/batchUpdateSeatStatus")
    public Integer batchUpdateSeatStatus(@RequestParam("seatIdList") List<Long> seatIdList)
    {
        return seatService.batchUpdateSeatStatus(seatIdList);
    }


    //批量回滚座位状态
    @RequestMapping("feign/batchRevertSeatStatus")
    public Integer batchRevertSeatStatus(@RequestParam("seatIdList") List<Long> seatIdList)
    {
        return seatService.batchRevertSeatStatus(seatIdList);
    }
}
